/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mycompany.psc.entities;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author A7med
 */
@Entity
@Table(name = "mobilization_items")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MobilizationItems.findAll", query = "SELECT m FROM MobilizationItems m"),
    @NamedQuery(name = "MobilizationItems.findById", query = "SELECT m FROM MobilizationItems m WHERE m.id = :id"),
    @NamedQuery(name = "MobilizationItems.findByQuantity", query = "SELECT m FROM MobilizationItems m WHERE m.quantity = :quantity"),
    @NamedQuery(name = "MobilizationItems.findByTitle", query = "SELECT m FROM MobilizationItems m WHERE m.title = :title"),
    @NamedQuery(name = "MobilizationItems.findByCategory", query = "SELECT m FROM MobilizationItems m WHERE m.category = :category"),
 
    @NamedQuery(name = "MobilizationItems.findByLoss", query = "SELECT m FROM MobilizationItems m WHERE m.loss = :loss")})
public class MobilizationItems implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @NotNull
    @Column(name = "quantity")
    private int quantity;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 64)
    @Column(name = "title")
    private String title;
    @Basic(optional = false)
    @NotNull
    
    @Column(name = "category")
    private double category;
    
    
    @Basic(optional = false)
    @NotNull
    @Column(name = "loss")
    private float loss;
    @JoinColumn(name = "parent", referencedColumnName = "item_id")
    @ManyToOne(optional = false)
    private Mobilization parent;

    public MobilizationItems() {
    }

    public MobilizationItems(Integer id) {
        this.id = id;
    }

    public MobilizationItems(Integer id, int quantity, String title, double category, float loss) {
        this.id = id;
        this.quantity = quantity;
        this.title = title;
        this.category = category;
        
        this.loss = loss;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public double getCategory() {
        return category;
    }

    public void setCategory(double category) {
        this.category = category;
    }

    public double getTotal() {
        return category*quantity;
    }

   

    public float getLoss() {
        return loss;
    }

    public void setLoss(float loss) {
        this.loss = loss;
    }

    public Mobilization getParent() {
        return parent;
    }

    public void setParent(Mobilization parent) {
        this.parent = parent;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MobilizationItems)) {
            return false;
        }
        MobilizationItems other = (MobilizationItems) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.mycompany.psc.entities.MobilizationItems[ id=" + id + " ]";
    }
     public MobilizationItems crateCopy(){
         MobilizationItems copy=new MobilizationItems();
        copy.setCategory(category);
        copy.setLoss(loss);
        copy.setQuantity(quantity);
        copy.setTitle(title);
        return copy;
        
    }
}
